package com.example.demo.example1.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;

import javax.persistence.*;
import java.util.Collection;

/**
 * Created by pengwan on 2017/7/23.
 */
@Entity
@Table(name = "student")
public class Student extends EntityId{
    @Column(name = "student_name")
    private String name;
    @Embedded
    @AttributeOverride(name = "room", column = @Column(name="dormitory"))
    private Address address;

    @ManyToOne // 关系所有者
    @JoinColumn(name = "department_id")
    private Department department;

    @ManyToMany // 关系所有者
    @JoinTable(name = "student_course", joinColumns = @JoinColumn(name = "student_id"), inverseJoinColumns = @JoinColumn(name="course_id"))
    // 多对多关系需要利用连接表，JoinTable 可以如上手工指定，也可省略由auto-ddl自动生成
    @JsonIgnore // 防止陷入了死循环
    private Collection<Course> courses;

    @OneToMany(mappedBy = "student") // 关系反方
    @JsonIgnore // 防止陷入了死循环
    private Collection<Score> scores;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    public Department getDepartment() {
        return department;
    }

    public void setDepartment(Department department) {
        this.department = department;
    }

    public Collection<Course> getCourses() {
        return courses;
    }

    public void setCourses(Collection<Course> courses) {
        this.courses = courses;
    }

    public Collection<Score> getScores() {
        return scores;
    }

    public void setScores(Collection<Score> scores) {
        this.scores = scores;
    }
}
